-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: consolidate tool logic into RooTool base class (fixes #7822) #7824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Created abstract RooTool base class to consolidate tool logic - Refactored WriteToFileTool to extend RooTool - Created ToolRegistry for centralized tool management - This addresses issue #7822 to consolidate tool definitions
- Created ToolAdapter to bridge existing code with new RooTool system - Allows gradual migration of tools without breaking existing functionality - Provides fallback to legacy implementations for unmigrated tools
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing my own code is like debugging in a mirror - everything looks backwards but the bugs are still mine.
| ): Promise<void> { | ||
| // For now, we'll delegate to the existing implementation | ||
| // In a full refactor, we would move all the logic here | ||
| const { writeToFileTool } = await import("../writeToFileTool") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentional? The WriteToFileTool is supposed to consolidate all logic but it's just delegating back to the legacy implementation. This defeats the purpose of the refactoring - we should either move all the logic here or clearly mark this as a transitional state with a TODO.
| import { Task } from "../../task/Task" | ||
| import { | ||
| ToolUse, | ||
| ToolResponse, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ToolResponse import appears to be unused. Could we remove it to keep the imports clean?
| * Get tool description map for prompts | ||
| * This replaces the old toolDescriptionMap | ||
| */ | ||
| getToolDescriptionMap(): Record<string, (args: any) => string | undefined> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we improve type safety here by using ToolArgs instead of any?
| getToolDescriptionMap(): Record<string, (args: any) => string | undefined> { | |
| getToolDescriptionMap(): Record<string, (args: ToolArgs) => string | undefined> { | |
| const descriptionMap: Record<string, (args: ToolArgs) => string | undefined> = {} |
| const displayNames: Record<string, string> = {} | ||
|
|
||
| // Map tool names to display names | ||
| const nameMapping: Record<ToolName, string> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This duplicates the TOOL_DISPLAY_NAMES constant from shared/tools.ts. Could we import and reuse the existing constant to avoid duplication and potential sync issues?
| return fetchInstructionsTool(cline, block, askApproval, handleError, pushToolResult) | ||
| } | ||
| default: | ||
| throw new Error(`Unknown tool: ${toolName}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we create a specific error class like UnknownToolError for better error handling and debugging? Generic errors make it harder to track down issues in production.
| */ | ||
| private registerTools(): void { | ||
| // Register each tool implementation | ||
| this.registerTool(new WriteToFileTool()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be helpful to add a TODO comment here tracking which tools still need migration? Something like:
| this.registerTool(new WriteToFileTool()) | |
| // Register each tool implementation | |
| this.registerTool(new WriteToFileTool()) | |
| // TODO: Migrate remaining tools (21 remaining): | |
| // Priority 1 (Core editing): | |
| // - ReadFileTool | |
| // - ApplyDiffTool | |
| // - ExecuteCommandTool | |
| // Priority 2 (Search/Navigation): | |
| // - SearchFilesTool | |
| // - ListFilesTool | |
| // - ListCodeDefinitionNamesTool | |
| // - CodebaseSearchTool | |
| // Priority 3 (Other): | |
| // ... etc |
|
This PR is incompletem the issue needs scoping |
Summary
This PR addresses Issue #7822 by introducing a new architecture for tool definitions that consolidates all tool-related logic into a single class structure.
Changes
New Architecture Components
RooTool Base Class (
src/core/tools/base/RooTool.ts)WriteToFileTool Implementation (
src/core/tools/implementations/WriteToFileTool.ts)ToolRegistry (
src/core/tools/ToolRegistry.ts)ToolAdapter (
src/core/tools/ToolAdapter.ts)Benefits
Migration Strategy
Next Steps
Testing
Feedback and guidance are welcome on this architectural approach before proceeding with the full migration.
Closes #7822
Important
Consolidates tool logic into
RooToolbase class, introducesToolRegistryfor centralized management, and migratesWriteToFileToolto new architecture.RooToolbase class inRooTool.tsfor consolidating tool logic.ToolRegistryinToolRegistry.tsfor centralized tool management.ToolAdapterinToolAdapter.tsfor backward compatibility with legacy tool invocations.WriteToFileToolto extendRooTool, consolidating its logic inWriteToFileTool.ts.ToolAdapterfor compatibility.This description was created by
for 4d97f77. You can customize this summary. It will automatically update as commits are pushed.